package com.huntero.hweather.bean;

import com.huntero.hweather.utils.ConvertChinese2Pinyin;
import com.lidroid.xutils.db.annotation.Column;
import com.lidroid.xutils.db.annotation.Table;

@Table(name = "citycode")
public class CityCode {

	@Column(column = "_id")
	public int _id;
	@Column(column = "key")
	public String key;
	@Column(column = "parentKey")
	public String parentKey;
	@Column(column = "level")
	public int level;
	@Column(column = "cnName")
	public String cnName;
	@Column(column = "pinyinName")
	public String pinyinName;
	@Column(column = "firstPinyin")
	public String firstPinyin;
	@Column(column = "isDirectCity")
	public int isDirectCity;
	@Column(column = "childCount")
	public int childCount;
	@Column(column = "orderId")
	public int orderId;

	public CityCode(String key, String parentKey, int level, int orderId, String cn,
			String pinyin, String first, boolean isDirectCity) {
		this.key = key;
		this.parentKey = parentKey;
		this.level = level;
		this.orderId = orderId;
		this.cnName = cn;
		this.pinyinName = pinyin;
		this.firstPinyin = first;
		this.isDirectCity = isDirectCity?1:0;
	}

	public CityCode(String string) {
		parse(string);
	}

	public CityCode() {
	}

	private void parse(String string) {
		if (string.startsWith("#"))
			return;
		string = string.trim();
		String[] strs = string.split("=");
		this.key = strs[0];
		this.parentKey = this.key.substring(0, 7);
		this.level = 3;
		this.cnName = strs[1];
		this.pinyinName = ConvertChinese2Pinyin.getPinyin(this.cnName);
		this.firstPinyin = this.pinyinName.substring(0, 1).toUpperCase();
		this.orderId = Integer.parseInt(this.key.substring(7));
		this.childCount = 0;
	}

	@Override
	public String toString() {
		return "insert into citycode(key,parentKey,level,cnName,pinyinName,firstPinyin,orderId,childCount,isDirectCity) values("
				+ "'"
				+ this.key
				+ "',"
				+ "'"
				+ this.parentKey
				+ "',"
				+ this.level
				+ ","
				+ "'"
				+ this.cnName
				+ "',"
				+ "'"
				+ this.pinyinName
				+ "',"
				+ "'"
				+ this.firstPinyin
				+ "',"
				+ this.orderId
				+ ","
				+ this.childCount + "," + this.isDirectCity + ");\n";
	}

	/**
	 * 浅级复制
	 */
	public CityCode clone() {
		CityCode n = new CityCode();
		n._id = this._id;
		n.childCount = this.childCount;
		n.cnName = this.cnName;
		n.firstPinyin = this.firstPinyin;
		n.isDirectCity = this.isDirectCity;
		n.key = this.key;
		n.level = this.level;
		n.orderId = this.orderId;
		n.parentKey = this.parentKey;
		n.pinyinName = this.pinyinName;
		return n;
	}

	public int get_id() {
		return _id;
	}

	public void set_id(int _id) {
		this._id = _id;
	}

	public String getKey() {
		return key;
	}

	public void setKey(String key) {
		this.key = key;
	}

	public String getParentKey() {
		return parentKey;
	}

	public void setParentKey(String parentKey) {
		this.parentKey = parentKey;
	}

	public int getLevel() {
		return level;
	}

	public void setLevel(int level) {
		this.level = level;
	}

	public String getCnName() {
		return cnName;
	}

	public void setCnName(String cnName) {
		this.cnName = cnName;
	}

	public String getPinyinName() {
		return pinyinName;
	}

	public void setPinyinName(String pinyinName) {
		this.pinyinName = pinyinName;
	}

	public String getFirstPinyin() {
		return firstPinyin;
	}

	public void setFirstPinyin(String firstPinyin) {
		this.firstPinyin = firstPinyin;
	}

	public int getIsDirectCity() {
		return isDirectCity;
	}

	public void setIsDirectCity(int isDirectCity) {
		this.isDirectCity = isDirectCity;
	}

	public int getChildCount() {
		return childCount;
	}

	public void setChildCount(int childCount) {
		this.childCount = childCount;
	}

	public int getOrderId() {
		return orderId;
	}

	public void setOrderId(int orderId) {
		this.orderId = orderId;
	}

}
